<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	template="/layout/template.xhtml"
	xmlns:a4j="http://richfaces.org/a4j">
	<ui:define name="stylefms">
		<link href="/stylesheet/theme.css" rel="stylesheet" type="text/css" />
		<link href="/stylesheet/fms.css" rel="stylesheet" type="text/css" />
		<link href="/stylesheet/panel.css" rel="stylesheet" type="text/css" />
		<link href="/stylesheet/debug.css" rel="stylesheet" type="text/css" />
	</ui:define>
	<ui:define name="varProjectName">
		<ui:param name="projectName" value="#{appRes['mod.fms.gnd.maintenances.medicamentos']}" />
	</ui:define>


	<ui:define name="body">
	
		<a4j:outputPanel id="msgContainer" ajaxRendered="true">
			<h:messages globalOnly="false" errorClass="msgError" styleClass="message" infoClass="msgInfo" />
		</a4j:outputPanel>

		<a4j:form id="MedicationGridForm" ajaxSingle="true">
			<rich:panel styleClass="table_back" rendered="#{not empty editMedication.allMedications}">
				<rich:datascroller align="center" for="MedicationGrid"
					maxPages="15" page="#{dataTableScrollerBean.scrollerPage}"
					renderIfSinglePage="false" />
					
				<rich:dataTable id="MedicationGrid"
					value="#{editMedication.allMedications}" var="medicine" rows="10"
					rendered="#{not empty editMedication.allMedications}">
					
					<rich:column>
						<f:facet name="header">Codigo</f:facet>
						<h:outputText value="#{medicine.cod}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Descripcion</f:facet>
						<h:outputText value="#{medicine.descrip}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header">Activo</f:facet>
						<h:outputText value="#{convertAssist.booleanToString(medicine.status)}" />
					</rich:column>
					
					<rich:column>
						<f:facet name="header">
							<h:outputText styleClass="columnHeader" value="Acciones" />
						</f:facet>
						<h:commandButton id="idCmdBorrar" value="Borrar"
							action="#{editMedication.dataToDelete(medicine.id)}"
							image="/img/icons/delete_data.png"
							onclick="if (!confirm('Esta usted seguro que quiere borrar el registro ?')) return false" />
						<rich:toolTip value="Borrar" for="idCmdBorrar" />
						<rich:spacer width="10" />
						<a4j:commandLink id="editAction"  action="#{editMedication.dataToEdit(medicine.id)}"
							oncomplete="#{rich:component('EditModalPanel')}.show()"
							reRender="EditModalPanel"
							immediate="true">

							<h:graphicImage id="editImg" url="/img/icons/edit.png"
								styleClass="actionsImages" />
						</a4j:commandLink>
						<rich:toolTip value="Editar" for="editAction" />
					</rich:column>

				</rich:dataTable>
			</rich:panel>
			
		</a4j:form>
		
		<a4j:form id="MedicationForm" ajaxSingle="true">
			
			<rich:panel styleClass="form">
				
				<div class="form_table">
					<div class="form_row">
						<div class="fields">
							<s:label for="MedicationCode">Codigo:</s:label>
							<h:inputText value="#{editMedication.medication.cod}"
									id="MedicationCode" 
									size="5">
									<rich:ajaxValidator 
		                    			event="onblur" 
		                    			onsubmit="validateStringField(
		                    				fieldObject = this, 
		                    				fieldMsgId = 'MedicationCodeMsg', 
		                    				required = 'true', 
		                    				requiredMsg = 'Favor ingrese el Codigo', 
		                    				chekForLength = 'true', 
		                    				min = 1, 
		                    				max = 5,
		                    				errorClass = 'msgErrorFloat')">
	           						</rich:ajaxValidator>	
							</h:inputText>	
							<div id="MedicationCodeMsg" class="inactiveMsg"></div>
						</div>
					</div>
					<div class="form_row">
						<div class="fields">
							<s:label for="MedicationDescrip">Descripcion:</s:label>
							<h:inputText 
									value="#{editMedication.medication.descrip}" 
									label="Descripcion"
									id="MedicationDescrip">
									<rich:ajaxValidator 
		                    			event="onblur" 
		                    			onsubmit="validateStringField(
		                    				fieldObject = this, 
		                    				fieldMsgId = 'MedicationDescripMsg', 
		                    				required = 'true', 
		                    				requiredMsg = 'Favor ingrese la Descripcion', 
		                    				chekForLength = 'true', 
		                    				min = 1, 
		                    				max = 30,
		                    				errorClass = 'msgErrorFloat')">
	           						</rich:ajaxValidator>
							</h:inputText>
							<div id="MedicationDescripMsg" class="inactiveMsg"></div>	
						</div>
					</div>
					<div class="form_row">
						<div class="fields">
							<s:label for="MedicationStatus">Activo:</s:label>
							<h:selectBooleanCheckbox 
								value="#{editMedication.medication.status}" 
								id="MedicationStatus"
								disabled="true">
								<a4j:support event="onblur" />
								</h:selectBooleanCheckbox>
						</div>
					</div>
				</div>

				<s:decorate template="/layout/displayButton.xhtml" styleClass="button_form">
					<a4j:commandButton value="Guardar"
						action="#{editMedication.saveNewData()}" reRender="MedicationForm, MedicationGridForm" styleClass="button"
						onclick="onRequestStart();"
						oncomplete="onRequestEnd('MedicationForm', undefined, #{editMedication.validateEntireForm});"/>
					<rich:spacer width="20px" />
					<a4j:commandButton value="Cancelar"
						onclick="#{rich:component('ConfirmationModalPanel')}.show()" styleClass="button" />
				</s:decorate>
					
			</rich:panel>
		</a4j:form>

		<rich:modalPanel  id="EditModalPanel" minwidth="800" minheight="400" 
			resizeable="flase" autosized="true"   >
			<f:facet name="header">
				<h:panelGroup>
					<h:outputText value="Actualizar Raza" />
				</h:panelGroup>
			</f:facet>
			<f:facet name="controls">
				<h:panelGroup>
					<h:graphicImage value="/img/close.png" style="cursor:pointer"
						id="hideEditApp" />
					<rich:componentControl for="EditModalPanel"
						attachTo="hideEditApp" operation="hide" event="onclick" />
				</h:panelGroup>
			</f:facet>
			<h:panelGroup id="idEditGroup">
			<!--  **** Include of the update page ****  -->
				<a4j:include viewId="/fms/gnd/maintenances/gndMedicationEdit.xhtml" />
			</h:panelGroup>
		</rich:modalPanel>
		
		<rich:modalPanel  id="ConfirmationModalPanel"
			resizeable="false" 
			autosized="true" 
			moveable="false" 
			style="border:2px solid #6FADDF">
			<a4j:form>
			<div class="globalMessage">
				<h:outputText value="Esta seguro que desea cancelar la operacion?" />
			</div>
			<s:decorate template="/layout/displayButton.xhtml" styleClass="trn_button_form"  style="width:270px; margin-top:0px; margin-left:auto; text-align:center;">
				<a4j:commandButton
					action="#{editMedication.cancelData()}"
					value="Aceptar" 
					id="AcceptConfirmation"
					reRender="MedicationForm, MedicationGridForm"
					oncomplete="#{rich:component('ConfirmationModalPanel')}.hide()"
					styleClass="button"/>
				<rich:spacer width="20px" />
				<a4j:commandButton value="Cancelar" id="CancelConfirmation"
					onclick="#{rich:component('ConfirmationModalPanel')}.hide()"
					styleClass="button" />
			</s:decorate>
			</a4j:form>
		</rich:modalPanel>
		
		<rich:modalPanel  id="CloseModalPanel"
			resizeable="false" 
			autosized="true" 
			moveable="false"
			style="border:2px solid #6FADDF;">
			<a4j:form>
			<div class="globalMessage">
				<h:outputText value="Esta seguro que desea cancelar la operacion?"/>
			</div>
			<center>
			<s:decorate template="/layout/displayButton.xhtml" styleClass="trn_button_form"  style="width:270px; margin-top:0px; margin-left:auto; text-align:center;">
				<a4j:commandButton
					action="#{editMedication.cancelData()}"
					value="Aceptar" 
					id="AcceptClose"
					reRender="MedicationForm, MedicationGridForm"
					oncomplete="#{rich:component('CloseModalPanel')}.hide();#{rich:component('EditModalPanel')}.hide();"
					styleClass="button"/>
				<rich:spacer width="20px" />
				<a4j:commandButton value="Cancelar" id="CancelClose"
					onclick="#{rich:component('CloseModalPanel')}.hide()"
					styleClass="button" />
			</s:decorate>
			</center>
			</a4j:form>
		</rich:modalPanel>
		
		<rich:modalPanel 
			id="wait-dialog" 
			resizeable="false" 
			autosized="false" 
			width="400" height="65" 
			moveable="false" 
			shadowOpacity="0"
			style="border:2px solid #6FADDF;-webkit-border-radius: 3px;-moz-border-radius: 3px;">
			<f:facet name="header">Un momento por favor..</f:facet>
			<h:graphicImage value="/img/ajax/ajax_load_04.gif" style="width:16px; float:left; padding-right:10px;"/>
			<h:outputText id="wait-dialog-process-text" value="Su peticion esta siendo procesada"/>
		</rich:modalPanel>
		

	</ui:define>

</ui:composition>